<?php
/**
 * 工程联系单控制器
 * @author ZhouYP
 **/
namespace Admin\Controller;
use Common\Controller\WahahabaseController;
class ConstructionLaisonNoteController extends WahahabaseController{

    public function _initialize() {
    	parent::_initialize();
    	$this->deal_model = D("Common/ConstructionLaisonNote");
		$this->att_model = D("Common/Attachment");
        $this->department_model = D("Common/Department");
        $this->consignee_model = D("Common/Consignee");
    }



	public function index(){
		/**搜索条件**/
		$where = "d.is_deleted <> 1";
		$submit_content = trim(I('request.submit_content'));
		if($submit_content){
			$where['submit_content'] = array('like',"%$submit_content%");
		}
		$this->getDepartLevel();
		$this->indexPageConstructionLaisonNoteFly($where);
	}





	/**
     *  添加
     */
	public function add(){
        //显示抄送数据
        $Department = $this->department_model->where(array('is_deleted' => 0))->field("id,department_name")->order("id DESC")->select();
        $this->assign("data", $Department);
		$this->display();
	}
    public function add_post(){
		$this->addFilePostConstructionLaisonNoteFly(U("ConstructionLaisonNote/index"), 4);
	}
	
	public function view(){
        $Department = $this->department_model->where(array('is_deleted' => 0))->field("id,department_name")->order("id DESC")->select();
        $this->assign("data", $Department);
        //
        $id = I('get.id',0,'intval');
        $Department = $this->consignee_model->field("department_id")->where(array('belong_to' => 'gclxd', 'table_id' => $id))->select();
        $this -> assign('selectDefault',$Department[0]['department_id']);
        $this->chaosong($id);
        //
		$this->getDepartLevel();
		$this->editFileDisplay(4);
	}

	/**
	 *  修改
	 */
	public function edit(){
        $Department = $this->department_model->where(array('is_deleted' => 0))->field("id,department_name")->order("id DESC")->select();
        $this->assign("data", $Department);
        //
        $id = I('get.id',0,'intval');
        $Department = $this->consignee_model->field("department_id")->where(array('belong_to' => 'gclxd', 'table_id' => $id))->select();
        $this -> assign('selectDefault',$Department[0]['department_id']);
        $this->chaosong($id);
        //
		$this->editFileDisplay(4);
	}
	public function edit_post(){
		$this->editFilePostConstructionLaisonNoteFly( U("ConstructionLaisonNote/index"), 4);
	}


	private function chaosong($id){
        $Department = $this->consignee_model->field("department_id")->where(array( 'belong_to' => 'gclxd', 'table_id' => $id))->select();
        $result = array();
        foreach ($Department as $key => $vo) {
            $result[] = $vo['department_id'];
        }
        $this->assign("dept2", json_encode($result));
    }





}


